package middlecontent.order;

import org.junit.Test;

public class ClassCastTest {
    @Test
    public void upCast(){
        int i = 10;

        long l = i;
        float f = i;
        double d = i;

        float m = l;
        double n = l;

        double k = f;
    }

    @Test
    //精度丢失问题
    public void upCast2(){
        int i = 123123123;

        float f = i;
        System.out.println(f);
        long l = 123123123123L;
        l = 123123123123123123L;
        double d = l;
        System.out.println(d);
    }

    public void upCast3(byte b){
        int i = b;
        long l = b;
        double d = b;
    }

    public void upCast4(short b){
        int i = b;
        long l = b;
        double d = b;
    }

    @Test
    public void downCast1(){
        long l = 10;
        int i = (int) l;
        short s = (short) l;
        char c = (char) l;
        byte b = (byte) l;

    }

    @Test
    public void downCast2(){
        float f = 10;
        int i = (int) f;
        short s = (short) f;
        char c = (char) f;
        byte b = (byte) f;

        double d = 10.2;
        byte b1 = (byte) d;

    }

    @Test
    public void downCast3(){
        short s = 1;
        byte b = (byte) s;

    }

    @Test
    public void downCast4(){
        short i = 128;
        byte b = (byte) i;
        System.out.println(b);

    }

    @Test
    public void downCast5(){
        double d = Double.NaN;
        int d1 = (int) d;
        System.out.println(d);
        System.out.println(d1);

        double d2 = Double.POSITIVE_INFINITY;
        System.out.println(d2);
        long l = (long) d2;
        int j = (int) d2;

        System.out.println(l);
        System.out.println(j);
    }




}
